from eventServer import eventServer
from keys import keys
from playerCube import PlayerCube
from inputMap import InputMap
from gameServer import gameServer

class HumanCube(PlayerCube):
    
    def __init__(self, player):
        PlayerCube.__init__(self)
        
        self.defaultVar("player",player)
        self.defaultVar("playerType","human")
        
        self.inputMap = gameServer.addObject("inputMap%d" % player,InputMap())
        self.inputMap.setVar("player",player)
        self.inputMap.load('inputMap%d.yml' % player)
        
        eventServer.register('walkLeft',self.walkLeft)
        eventServer.register('walkRight',self.walkRight)
        eventServer.register('jump',self.doJump)
        eventServer.register('drop', self.doFall)
        eventServer.register('goFast',self.doGoFast)
        eventServer.register('goFast',self.doItemUse)
        
    #change to analog
    def walkLeft(self, cmd, args):
        #print cmd, args
        if args['player'] == self.getVar('player'):
            if args['bin']:
                self.walk(True)
            else:
                self.stopWalk()
                
    def walkRight(self, cmd, args):
        #print cmd, args
        if args['player'] == self.getVar('player'):
            if args['bin']:
                self.walk(False)
            else:
                self.stopWalk()
                
    def doJump(self, cmd, args):
        #print cmd, args
        if args['player'] == self.getVar('player'):
            if args['bin']:
                self.jump()
            else:
                self.stopJump()
            
    def doFall(self, cmd, args):
        if args['player'] == self.getVar('player') and args['bin']:
            self.fall()
            
    def doItemUse(self, cmd, args):
        if args['player'] == self.getVar("player"):
            if args['bin']:
                self.grabItem()
            else:
                self.useItem()
            
    def doGoFast(self, cmd, args):
        if args['player'] == self.getVar("player"):
            if args['bin']:
                self.goFast()
            else:
                self.stopGoFast()
        
    #def keyDown(self, cmd, args):
        #key = args["key"]
        
        #if key == keys["a"]:
            #self.walk(True)
        #if key == keys["d"]:
            #self.walk(False)
        #if key == keys["w"]:
            #self.jump()
            
    #def keyUp(self, cmd, args):
        #key = args["key"]
        
        #if key == keys["a"]:
            #self.stop()
        #if key == keys["d"]:
            #self.stop()
